import Vue from 'vue';
import {Modal} from 'ant-design-vue';
import GateWayConfiguration from '@/components/flow/GateWayConfiguration/GateWayConfiguration.vue';
import FlowModelInstance from '@/components/flow/typs/FlowModelInstance.js';
import {createElement, openModal} from '@/utils/index.js';

export default class EditGatewayCommand {
  supportInstance;
  nodeId;

  constructor(supportInstance, nodeId) {
    this.supportInstance = supportInstance;
    this.nodeId = nodeId;
  }

  serve() {
    let flowModelInstance = new FlowModelInstance(this.supportInstance.getModel());
    openModal(GateWayConfiguration
      , {editingNode: flowModelInstance.getNodeById(this.nodeId),}
      , (node) => this.ok(node));
  }

  ok(node) {
    let flowModelInstance = new FlowModelInstance(this.supportInstance.getModel());
    flowModelInstance.replaceNode(node);
    this.supportInstance.setModel(flowModelInstance.getModelString());
  }
}